package number_operatation.nowcoder.easy;

/**
 * @author bruin_du
 * @description 不用加减乘除做加法
 * https://www.nowcoder.com/questionTerminal/59ac416b4b944300b617d4f7f111b215
 * @date 2022/5/25 19:34
 **/
public class Add {
    public int add(int num1,int num2) {
        int sum = 0,carry = 0;
        while(num2 != 0){
            sum = num1 ^ num2;
            carry = (num1 & num2) << 1;
            num1 = sum;
            num2 = carry;
        }
        return num1;
    }
}
